package com.ludomancy.sos64;


import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import com.ludomancy.gamelib.Randomizer;
import com.ludomancy.gamelib.Sound;
import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;

public class EndGameWidget extends Widget
{
	private long nextFlash = 0;
	private int flash;
	
	public EndGameWidget(Widget parent, Rectangle area)
	{
		super(parent, area);
		Game.game.loadTerrain(true);
		Sound.play("tono.wav");
	}
	
	public void update()
	{
		if(System.currentTimeMillis() > nextFlash)
		{
			if(nextFlash != 0)
			{
				flash = 5;
			}
			nextFlash = System.currentTimeMillis() + Randomizer.getRandom(4000,8000);
		}
	}
	
	public void paint(Graphics g)
	{
		if(flash > 0)
		{
			flash--;
			parent.paint(g);
		}
		else
		{
			g.setColor(Color.BLACK);
			g.fillRect(0, 0, getWidth(), getHeight());
			g.setColor(Color.RED);
			int offsetY = 10;
			int offsetX = 0;
			if(System.currentTimeMillis() % 13 == 0)
			{
				offsetX = 14;
			}
			Utils.drawMultiline(g, "System Core Dumped\nCheck:\n<SERVER_ROOT>/minidump.log\nfor a more info. Complete dump not activated.\nLast error in stack:\nUnvalid write access to location 0xbadc0de64.", getWidth()-10, 5+offsetX, offsetY);
		}
	}
}
